package cn.zjj.org.controller;

import cn.zjj.basic.util.JsonResult;
import cn.zjj.basic.util.PageList;
import cn.zjj.org.domain.ShopAuditLog;
import cn.zjj.org.query.ShopAuditLogQuery;
import cn.zjj.org.service.IShopAuditLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*@RestController
@RequestMapping("/shopAuditLog")*/
@Api(value = "审核的API",description="审核相关的CRUD功能")
public class ShopAuditLogController {

    @Autowired
    private IShopAuditLogService shopAuditLogService;

    //查询所有
    @GetMapping
    @ApiOperation(value = "查询所有数据" )
    public List<ShopAuditLog> selectAll(){

        return shopAuditLogService.selectAll();
    }

    //查询单个
    @GetMapping("/{id}")
    @ApiOperation(value = "查询一条数据" )
    public ShopAuditLog selectById(@PathVariable("id") Long id){
        return shopAuditLogService.selectById(id);
    }

    //删除单个
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除一个数据" )
    public JsonResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.delete(id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me(false,"操作失败");
        }
    }

    //添加或修改
    @PutMapping
    @ApiOperation(value = "添加或修改数据" )
    public JsonResult updateOrAdd(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if(shopAuditLog.getId()==null){
                shopAuditLogService.insert(shopAuditLog);
            }else {
                shopAuditLogService.update(shopAuditLog);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me(false,"操作失败");
        }
    }

    //分页和高级查询
    @PostMapping
    @ApiOperation(value = "分页查询或高级查询" )
    public PageList<ShopAuditLog> queryPage(@RequestBody ShopAuditLogQuery query){
        return shopAuditLogService.selectQuery(query);
    }

    @PatchMapping
    @ApiOperation(value = "批量删除" )
    public JsonResult delete(@RequestBody List<Long> ids){
        try {
            shopAuditLogService.patchDel(ids);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me(false,"操作失败");
        }
    }
}
